package com.lxj.database;

import com.lxj.database.user.UserInfoTable;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class APP_SQLiteOpenHelper extends SQLiteOpenHelper {
	private static String DB_NAME = "lxj.db";
	private static int DB_VERSION = 1;

	public APP_SQLiteOpenHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}
	
	public void setDBName(String aDBName, int aVersion)
	{
		DB_NAME = aDBName;
		DB_VERSION = aVersion;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		createData(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		updateData(db, oldVersion, newVersion);
	}

	public static void createData(SQLiteDatabase db) {

		
		
		String create_table_userinfo = UserInfoTable.createTable();
		
		if(create_table_userinfo != null)
		{			
			db.execSQL(create_table_userinfo);
		}
	}
	
	private static void updateData(SQLiteDatabase db, int oldVersion, int newVersion) {

		
		
		String create_table_userinfo = UserInfoTable.updateTable(oldVersion, newVersion);
		
		if(create_table_userinfo != null)
		{			
			db.execSQL(create_table_userinfo);
		}
	}

	public static void clearData(SQLiteDatabase db) {
		createData(db);
	}
}
